<?php

/**
 * 系统控制器
 */
namespace Admin\Controller;

use Admin\Model\AddrModel;
use Think\Controller;

class AddrController extends Controller
{
    private $_M;//地址模型

    public function __construct()
    {
        parent::__construct();
        $this->_M=new AddrModel('addr');
        ajaxHeader();
    }

    /**
     * 获取所有站点
     */
    public function getAllAddr()
    {
        $addrData=$this->_M->getAllAddr();
        echo json_encode($addrData);

    }


    /**
     * 添加站点
     */
    public function addAddr()
    {
        $postData=getHttpData();

        //检测数据合法性
        if(count($postData)<4){
            doResopnse('1001',"提交数据不完整");
        }


        //数据合法
        if(count($postData) >=4 ){

            //收集数据
            $from=$postData[from];
            $to=$postData[to];
            $price=$postData[price];
            $depart_time=$postData[depart_time];
            $depart_condition=$postData['depart_condition'];
            $status="1";

            $sql="insert into bus_addr (addr_from, addr_to, addr_depart_time, addr_price, addr_status,addr_depart_condition) VALUES ('$from','$to','$depart_time','$price','$status','$depart_condition')";
            if(D()->execute($sql) > 0){
                responseOk();
            }
        }


    }


    public function delAddr(){
        $addrId=$_GET['addrId'];
        if($this->_M->delete($addrId)){
            responseOk();
        }else{
            doResopnse("2001","服务器未知错误(2001)");
        }

    }



}